#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#       addgame.py
#       
#       Copyright 2011 www.soycode.com
#       
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 3 of the License, or
#       (at your option) any later version.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

"""
Accept a request from Mochi Media, fetch and install specified game from feed.
www.soycode.com
"""

# standard
import cgi
import os
# enable for debugging
#import cgitb
#cgitb.enable()
# package
import makesite

PUBLISHER_ID = 'ENTER_YOUR_PUBLISHER_ID_HERE'


def main():
  print 'Content-type: text/html\n'
  game_tag = cgi.FieldStorage().getvalue('game_tag')
  if game_tag:
    makesite.autopost.fetch_game(PUBLISHER_ID, game_tag, './games')
    makesite.UpdateSite([game_tag])
    # todo: make chmoding smarter (right now python os.chmod can't recurse)
    os.system('chmod -R 755 games/')


if __name__ == "__main__":
  main()

